import { createSlice } from "@reduxjs/toolkit";
import { Request } from "@/utils/request.js";
// 初始化状态对象，用于存储应用的状态
const initialState = {
  employee: {
    account: '',
    name: '',
    gender: '',
    phoneNumber: '',
    identificationNumber: '',
  },
};

// 创建一个名为 "dish" 的 Redux store，并传入初始状态
const dishStore = createSlice({
  name: "dish",
  initialState,
  reducers: {
  },
})

/**
 * 添加菜品
 * @param {Object} dish - 需要添加的菜品对象
 * @returns {Promise} - 返回一个 Promise 对象，表示请求的结果
 */
const addDish = (dish) => {
  return Request("/dishManagement/add", dish).then((res) => {
    return res;
  });
}

/**
 * 添加菜品口味
 * @param {Object} flavor - 需要添加的菜品口味对象
 * @returns {Promise} - 返回一个 Promise 对象，表示请求的结果
 */
const addFlavor = (flavor) => {
  return Request("/dishManagement/addFlavor", flavor).then((res) => {
    return res;
  });
}

/**
 * 获取菜品口味列表
 * @returns {Promise} - 返回一个 Promise 对象，表示请求的结果
 */
const getDishCategoryList = () => {
  return Request("/dishManagement/getDishCategoryList", null).then((res) => {
    return res;
  });
}

/**
 * 获取菜品列表
 * @param {Object} dish - 查询条件对象
 * @returns {Promise} - 返回一个 Promise 对象，表示请求的结果
 */
const getDishList = (dish) => {
  return Request("/dishManagement/getDishList", dish).then((res) => {
    return res;
  });
}

/**
 * 获取口味列表
 * @param {Object} dish - 查询条件对象
 * @returns {Promise} - 返回一个 Promise 对象，表示请求的结果
 */
const getFlavorList = (dish) => {
  return Request("/dishManagement/getFlavorList", dish).then((res) => {
    return res;
  });
}

/**
 * 获取口味列表
 * @param {Object} dish - 查询条件对象
 * @returns {Promise} - 返回一个 Promise 对象，表示请求的结果
 */
const getFlavorByDishId = (dishId) => {
  return Request("/dishManagement/getFlavorByDishId", dishId).then((res) => {
    return res;
  });
}

const deleteDish = (dishId) => {
  return Request("/dishManagement/deleteDish", dishId).then((res) => {
    return res;
  });
}

const updateDish = (dish) => {
  return Request("/dishManagement/updateDish", dish).then((res) => {
    return res;
  });
}

// 导出函数和 Redux store 的 reducer
export { addDish, addFlavor, getDishCategoryList, getDishList, getFlavorList, getFlavorByDishId, deleteDish, updateDish };
export default dishStore.reducer;
